<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name=" apple-mobile-web-app-capable" />
    <!-- 隐藏状态栏  -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <!-- <title>注册</title> -->
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/details.css">
</head>

<body>
    <header>
        <div class="wrapper clearfix">
            <div class="login_fl fl">
                <a href="javascript:back()" class="login_icon"><img src="img/srh_icon.png" alt=""></a>
            </div>
            <h1>注册</h1>
        </div>
    </header>
    <article class="mod-forgot p10 login_mod" style="position:inherit;">
        <input type="text" class="re_password" id="phoneNum" placeholder="手机号">
        <input type="text" class="re_password" id="captcha" placeholder="校验码">
        <a class="gain_vcode gain_vcode2" id="captchaBtn" href="javascript:void(0)">获取验证码</a>
        <input type="password" class="re_password" id="password" placeholder="密码(不少于6位)">
        <input type="button" class="next_step" value="注册" onclick="submit()">
        <a class="agree_txt" href="agreement.html">注册即视为同意<span>《去嗨用户协议》</span></a>
    </article>
    <!-- JS begin -->
    <script src="js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="js/constants.js"></script>
    <script src="js/common.js"></script>
    <script>
    var urlCaptcha = server_host + '/reg/sendSmsToUserForRegistration.do';
    var urlSubmit = server_host + '/reg/useRegistration.do';
    var regex = /^1[3|4|5|8|7][0-9]\d{4,8}$/;

    var captchaBtn = $('#captchaBtn');

    var remainTime = 60;

    var params = getParameterByName('params');
    var fr = getParameterByName('fr');

    function captchaClick() {
        var phoneNum = $('#phoneNum').val();
        if (regex.test(phoneNum)) {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: urlCaptcha + '?phoneNum=' + phoneNum,
                success: function(data) {
                    console.log(data);
                    if (data.code == 0) {
                        captchaBtn.addClass('act');
                        captchaBtn.unbind('click');
                        captchaBtn.html(remainTime);
                        var timer = setInterval(function() {
                            remainTime--;
                            captchaBtn.html(remainTime);
                            if (remainTime == 0) {
                                clearInterval(timer);
                                captchaBtn.removeClass('act');
                                captchaBtn.bind('click', captchaClick);
                                captchaBtn.html('获取');
                                remainTime = 60;
                            }
                        }, 1000);
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            alert('请输入正确的手机号码！');
        }
    }

    function submit() {
        var phoneNum = $('#phoneNum').val();
        var captcha = $('#captcha').val();
        var password = $('#password').val();
        if (phoneNum.trim() == '') {
            alert('请输入手机号码！');
        } else if (!regex.test(phoneNum)) {
            alert('请输入正确的手机号码！');
        } else if (captcha.trim() == '') {
            alert('请输入验证码！');
        } else if (password.trim() == '') {
            alert('请输入密码！');
        } else {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: urlSubmit + '?phoneNum=' + phoneNum + '&passwd=' + password + '&vNum=' + captcha,
                success: function(data) {
                    console.log(data);
                    if (data.isSuccess) {
                        alert(data.msg);
                        location.href = 'login.html?params=' + params + '&fr=' + fr;
                    } else {
                        alert(data.msg);
                    }
                }
            });
        }
    }

    function back() {
        location.href = 'login.html?params=' + params + '&fr=' + fr;
    }

    $(document).ready(function() {
        captchaBtn.bind('click', captchaClick);
    });
    </script>
    <!-- JS end -->
</body>
<span style="display:none;"><script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1255764485'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s95.cnzz.com/z_stat.php%3Fid%3D1255764485%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));</script></span>
<script>
    _maq.push(['_setMaq', 'register']);
</script>
</html>
